/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package clases;

import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jorge
 */
public class PnuevoCliente extends javax.swing.JPanel {
    Statement ST;
   Ventana principal;

    /**
     * Creates new form NCliente
     */
    public PnuevoCliente(Ventana aThis) {
        initComponents();
        principal = aThis;
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        jTextField1.setText("jTextField1");

        setBackground(new java.awt.Color(170, 198, 210));
        setLayout(null);

        jLabel1.setFont(new java.awt.Font("Broadway", 1, 18)); // NOI18N
        jLabel1.setText("Compu System/");
        add(jLabel1);
        jLabel1.setBounds(10, 0, 169, 38);

        jLabel2.setFont(new java.awt.Font("Lucida Bright", 1, 14)); // NOI18N
        jLabel2.setText("nuevo Cliente");
        add(jLabel2);
        jLabel2.setBounds(185, 11, 121, 17);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Nombre");
        add(jLabel3);
        jLabel3.setBounds(22, 58, 43, 15);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Apellido P");
        add(jLabel4);
        jLabel4.setBounds(12, 100, 53, 15);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Sexo");
        add(jLabel5);
        jLabel5.setBounds(38, 211, 27, 15);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel6.setText("Apellido M");
        add(jLabel6);
        jLabel6.setBounds(10, 138, 55, 15);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel7.setText("Edad");
        add(jLabel7);
        jLabel7.setBounds(38, 180, 27, 15);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel8.setText("Limite Credito");
        add(jLabel8);
        jLabel8.setBounds(234, 197, 75, 15);

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel9.setText("Direccion");
        add(jLabel9);
        jLabel9.setBounds(246, 58, 49, 15);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel10.setText("telefono");
        add(jLabel10);
        jLabel10.setBounds(249, 100, 46, 15);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel11.setText("Fecha Autorizacion");
        add(jLabel11);
        jLabel11.setBounds(193, 148, 102, 15);
        add(jTextField2);
        jTextField2.setBounds(75, 56, 120, 20);
        add(jTextField3);
        jTextField3.setBounds(75, 98, 120, 20);
        add(jTextField4);
        jTextField4.setBounds(75, 136, 120, 20);
        add(jTextField5);
        jTextField5.setBounds(75, 178, 120, 20);
        add(jTextField6);
        jTextField6.setBounds(75, 209, 120, 20);
        add(jTextField7);
        jTextField7.setBounds(313, 56, 145, 20);
        add(jTextField8);
        jTextField8.setBounds(313, 98, 145, 20);
        add(jTextField9);
        jTextField9.setBounds(313, 146, 145, 20);
        add(jTextField10);
        jTextField10.setBounds(327, 195, 131, 20);

        jButton1.setText("TERMINAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1);
        jButton1.setBounds(52, 254, 117, 43);

        jButton2.setText("Guardar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        add(jButton2);
        jButton2.setBounds(342, 259, 88, 33);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        
         this.setVisible(false);
        this.setEnabled(false);
        
        principal.pGerente.setVisible(true);
        principal.pGerente.setEnabled(true);
                principal.setSize(900,600);

        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        
        
        String nombre;
           String Ap;
           String Am;
           int edad;
           char sexo;
           String Dir;
           String Tel;
           String FechA;
           String LimiteC;
           
   if(jTextField1.getText().length()>0 && jTextField2.getText().length()>0 &&jTextField3.getText().length()>0 &&jTextField4.getText().length()>0 &&jTextField5.getText().length()>0 
      && jTextField6.getText().length()>0 && jTextField7.getText().length()>0 &&jTextField8.getText().length()>0 && jTextField9.getText().length()>0 &&
      jTextField10.getText().length()>0 ) {
       try{
            nombre = jTextField2.getText();
           Ap = jTextField3.getText();
           Am = jTextField4.getText();
           edad =Integer.parseInt( jTextField5.getText());
           sexo = jTextField5.getText().charAt(0);
           Dir =  jTextField7.getText();
           Tel =  jTextField8.getText();
           FechA =  jTextField9.getText();
           LimiteC =  jTextField10.getText();
   
    ST.executeUpdate("INSERT INTO cliente_credito(Nombre,Apellido_P,Apellido_M,Edad,Sexo,Direccion,Telefono,Fecha_Autorizacion,Limite_De_Credito) "
                + "values('"+nombre+"','"+Ap+"','"+Am+"','"+edad+"','"+sexo+"','"+Dir+"','"+Tel+"','"+FechA+"','"+LimiteC+"')");
     
    System.out.println(""+nombre+",'"+Ap+"','"+Am+"','"+edad+"','"+sexo+"','"+Dir+"','"+Tel+"','"+FechA+"','"+LimiteC+"')");
                System.out.println("\nagregado....");
           
           
             jTextField2.setText("");
             jTextField3.setText("");
             jTextField4.setText("");
             jTextField5.setText("");
             jTextField6.setText("");
             jTextField7.setText("");
             jTextField8.setText("");
             jTextField9.setText("");
             jTextField10.setText("");
   } catch (SQLException ex){
    Logger.getLogger(PnuevoCliente.class.getName()).log(Level.SEVERE, null, ex);
}    
           
           
        // TODO add your handling code here:
    }
        
        
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    // End of variables declaration//GEN-END:variables

    void setStatement(Statement stmt) {
    ST = stmt;
    
    
    }
}
